package com.am.servlet;

import com.am.bean.Menu;
import com.am.service.MenuService;
import com.utils.Meg;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class  MenuServlet {

    @Autowired
    private MenuService menuService;

    @RequestMapping("/menuView")
    public String menuView(){
        return "menu/menu";
    }

    @RequestMapping("/menuEditView")
    public String menuEditView(){
        return "menu/menuPage";
    }

    @RequestMapping("/menuAddView")
    public String menuAddView(){
        return "menu/menuAdd";
    }

    @ResponseBody
    @RequestMapping("/menuData")
    public Meg menuData(@Param("page") String page, @Param("limit") String limit){
        return Meg.success().add("data",menuService.selectAll(limit,page));
    }

    @ResponseBody
    @RequestMapping("/menuInsert")
    public Meg menuInsert(Menu menu){
        int i = menuService.insert(menu);
        if (i>0)
            return Meg.success();
        else
            return  Meg.file();
    }

    @ResponseBody
    @RequestMapping("/menuUpdate")
    public Meg menuUpdate(Menu menu){
        System.out.println(menu.getMenuName());
        int i = menuService.update(menu);
        if (i>0)
            return Meg.success();
        else
            return  Meg.file();
    }

    @ResponseBody
    @RequestMapping("/menuDelete")
    public Meg menuDelete(@Param("id") Integer id){
        int i = menuService.delete(id);
        if (i>0)
            return Meg.success();
        else
            return  Meg.file();
    }
    @ResponseBody
    @RequestMapping("/menuActivate")
    public Meg menuAction(@Param("id")Integer id,@Param("menuActivate")String menuActivate){
        menuService.Action(id,menuActivate);

        return Meg.success();
    }
}
